package org.deadline.model.user;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.baseapp.BaseEntity;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

@Entity
public class UserGroupMember extends BaseEntity  implements Serializable {

    @NotNull
    @ManyToOne
    private Person person;

    @NotNull
    @ManyToOne
    private Person createdBy;

    @NotNull
    @ManyToOne
    private UserGroup userGroup;

    private transient boolean notifyMail;

    private transient boolean notifySMS;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="user_group_member_seq_gen",sequenceName="user_group_member_seq")
	@GeneratedValue(generator="user_group_member_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	private static final long serialVersionUID = 1L;

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	public static UserGroupMember fromJsonToUserGroupMember(String json) {
        return new JSONDeserializer<UserGroupMember>().use(null, UserGroupMember.class).deserialize(json);
    }

	public static String toJsonArray(Collection<UserGroupMember> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<UserGroupMember> fromJsonArrayToUserGroupMembers(String json) {
        return new JSONDeserializer<List<UserGroupMember>>().use(null, ArrayList.class).use("values", UserGroupMember.class).deserialize(json);
    }

	public Person getPerson() {
        return this.person;
    }

	public void setPerson(Person person) {
        this.person = person;
    }

	public Person getCreatedBy() {
        return this.createdBy;
    }

	public void setCreatedBy(Person createdBy) {
        this.createdBy = createdBy;
    }

	public UserGroup getUserGroup() {
        return this.userGroup;
    }

	public void setUserGroup(UserGroup userGroup) {
        this.userGroup = userGroup;
    }

	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	}
